package com.fairytask.ui.item
{
	import com.fairytask.engine.components.BaseItem;
	import com.fairytask.engine.components.clip.Clip;
	import com.fairytask.engine.components.text.Label;
	import com.fairytask.engine.define.ResConfig;
	import com.fairytask.managers.ResManager;
	import com.fairytask.resource.StaticIni;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	
	/**
	 * 包裹物品 
	 * @author xujh
	 * 
	 */
	public class BagItemBak extends BaseItem
	{
		//========================================
		private var _bgMc			:MovieClip;			//背景物品框
//		private var _imgBg			:Sprite;			//物品图片背景填充
		private var _bagImg		:Clip;				//物品图片
		private var _numLab		:Label;				//物品数量
		private var _source		:String;			//路径
		private var _pos			:int;
		
		private var _configID		:int;
//		private var _isNeedBg		:Boolean	= false;	//是否需要添加背景
		private var _hasItemBg		:Boolean	= false;	//是否显示背景物品框
		
		public function BagItemBak()
		{
			init();
			initEvent();
		}
		
		/**
		 * 初始化 
		 * 
		 */
		private function init():void
		{
			_bagImg	=	new Clip(true,onLoad);
			_numLab		=	new Label();
			_numLab.x = 35;
			_numLab.y = 35;
			/*_imgBg		=	drawBg();
			_imgBg.x = 2;
			_imgBg.y = 2;
			//默认不显示背景
			_imgBg.visible = false;
			addChild(_imgBg);*/
			addChild(_bagImg);
			addChild(_numLab);
		}
		
		private function initEvent():void
		{
			
		}
		
		private function onLoad(val:String):void
		{
			_bagImg.width = 50;
			_bagImg.height= 50;
			_bagImg.x = 4;
			_bagImg.y = 4;
		}
		
		/**
		 *	绘制背景 
		 */		
		private function drawBg():Sprite
		{
			var sp		:Sprite	=	new Sprite();
			sp.graphics.beginFill(0x000C1A);
			sp.graphics.drawRoundRect(0,0,50,50,10);
			sp.graphics.endFill();
			return sp;
		}
		
		public function get configID():int
		{
			return _configID;
		}
		
		/**
		 * 设置configID，加载图片 
		 * @param val
		 * 
		 */
		public function set configID(val:int):void
		{
			//不相同重新加载物品图片
			if(_configID != val)
			{
				//先清空
				_bagImg.clear();
				if(val != 0)
				{
					_bagImg.source = ResConfig.iconPath + StaticIni.getIniVar(val,"Icon") + ResConfig.iconImg;
//					_bagImg.width	= 35;
//					_bagImg.height	= 35;
				}
				/*else
				{
					this.isNeedBg = false;
				}*/
			}
			_configID = val;
		}
		
		public function get source():String
		{
			return _source;
		}
		
		public function set source(val:String):void
		{
			if(_source != val)
			{
				_source = val;
				//先清空
				_bagImg.clear();
				if(null != _source)
				{
//					_bagImg.source = ResConfig.iconPath + _configID + ".png";
					_bagImg.source = _source;
//					_bagImg.width	= 35;
//					_bagImg.height	= 35;
				}
				/*else
				{
					this.isNeedBg = false;
				}*/
			}
		}
		
		/**
		 * 是否显示背景物品框 
		 * @param val
		 * 
		 */
		public function set hasItemBg(val:Boolean):void
		{
			_hasItemBg = val;
			if(_hasItemBg)
			{
				_bgMc 			= ResManager.newResClass("CustSkin_017") as MovieClip;
				_bgMc.x = 1;
				_bgMc.y = 2
				_bgMc.width = _bgMc.height = 56;
				addChildAt(_bgMc,0);
			}
		}
		
		public function get hasItemBg():Boolean
		{
			return _hasItemBg;
		}
		
		/**
		 * 是否需要物品图片背后填充色 
		 * @param val
		 * 
		 */
		/*public function set isNeedBg(val:Boolean):void
		{
			_isNeedBg = val;
			_isNeedBg = true ? _imgBg.visible=true : _imgBg.visible=false;
		}
		
		public function get isNeedBg():Boolean
		{
			return _isNeedBg;
		}*/
		
		/**
		 * 设置物品数量 
		 * @param val
		 * 
		 */
		public function set itemNum(val:int):void
		{
			_numLab.htmlStr = val.toString();
		}
		
		public function get itemNum():int
		{
			return int(_numLab.htmlStr);
		}
		
		/**
		 * 设置物品数量 
		 * @param val
		 * 
		 */
		public function set pos(val:int):void
		{
			_pos = val;
		}
		
		public function get pos():int
		{
			return _pos;
		}
		
		public function get itemPhoto():Clip
		{
			return _bagImg;
		}
		
		public function clearPhoto():void
		{
			_source = null;
			_bagImg.clear();
		}
	}
}